import React from 'react';
import jsPDF from 'jspdf';
import { AutoText as jsPDFAutoText } from 'jspdf-autotext';
import '../assets/SourceHanSerifCN-Regular';

function Home() {
  const exportPDF = () => {
    const pdfFile = new jsPDF();

    pdfFile.setFont('SourceHanSerifCN', 'normal');
    pdfFile.setFontSize(10);

    const AutoText = new jsPDFAutoText({ pdfFile });

    const renderedPositions = AutoText.render([
      { text: '离骚', indent: 15 },
      { text: '屈原', indent: 15 },
      '帝高阳之苗裔兮，朕皇考曰伯庸。',
      '摄提贞于孟陬兮，惟庚寅吾以降。',
      '皇览揆余初度兮，肇锡余以嘉名:名余曰正则兮，字余曰灵均。',
    ]);

    AutoText.addPage();

    AutoText.render([
      { text: '赋得古原草送别', indent: 14 },
      { text: '白居易', indent: 15 },
      '离离原上草，一岁一枯荣。',
      '野火烧不尽，春风吹又生。',
      '远芳侵古道，晴翠接荒城。',
      '又送王孙去，萋萋满别情。',
    ]);

    pdfFile.save();
  };

  return <button onClick={exportPDF}>测试</button>;
}

export default Home;
